home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / mail / parsegrabs11.lha / ParseGrabs.br
Text File  |  1995-09-03  |  5KB  |  192 lines

  1. /*
  2. ** $VER: ParseGrabs.br 1.1 (3.9.95)
  3. **
  4. ** ParseGrabs.br will check for any grabs in the download directory and
  5. ** parse them.  If there are active events which have not been deleted it
  6. ** will list these events and then ask the user whether to delete them or
  7. ** not.
  8. **
  9. ** Requires C:List, C:Delete, C:Ask and C:Resident to be present.
  10. **
  11. ** Set makeresident to 1 below for some extra speed.
  12. **
  13. ** 
  14. ** Todo:  Close window after parsing if fromthor = 1. HOW?!?
  15. **
  16. ** 1.1 (28.8.95)
  17. ** ~~~~~~~~~~~~~
  18. ** New:   GUI interface if run from Thor
  19. **
  20. ** Fixed: Event packing didn't always work as it should
  21. **        C:List was never made resident
  22. **        Misc. stuff
  23. **
  24. */
  25.  
  26. options results
  27.  
  28. signal on break_c
  29. signal on error
  30. signal on halt
  31.  
  32. pubscreen    = "Workbench"        /* Public screen to open progressbars on
  33.                                      if run from Shell */
  34. makeresident = 1                  /* Make list resident before starting.
  35.                                      0 = FALSE, 1 = TRUE */
  36. remresident  = 1                  /* Remove list from resident list after
  37.                                      finishing. 0 = FALSE, 1 = TRUE */
  38.  
  39. tiopen = 0; glopen = 0
  40.  
  41. EDB_DELETED       = 0    /* Event is deleted */
  42. EDB_DONE          = 2    /* Event is done */
  43. EDB_ERROR         = 3    /* Error performing this event */
  44. EDB_FREEZE        = 5    /* Event is frozen. Will not be done as long as this flag is set. */
  45.  
  46. /* See if I'm run from Thor */
  47.  
  48. if left(address(), 5) = 'THOR.' then do
  49.     thorport = address()
  50.     address(thorport)
  51.     GETGLOBALCONFIG STEM globcfg
  52.     if rc ~= 0 then call displayerror(0)
  53.     pubscreen = globcfg.PUBSCREENNAME
  54.     LOCKGUI
  55.     fromthor = 1
  56.     end
  57. else fromthor = 0
  58.  
  59. /* Open BBSREAD ARexx port */
  60.  
  61. if ~show('p', 'BBSREAD') then do; address command; "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"; "WaitForPort BBSREAD"; end
  62.  
  63. /* Find Thor's path */
  64.  
  65. call open(pn, 'ENV:Thor/THORPATH', 'R')
  66. thorpath = readln(pn)
  67. call close(pn)
  68.  
  69. /* Fetch some needed info from bbsread */
  70.  
  71. address(bbsread)
  72. GETGLOBALDATA globdata
  73. if rc ~= 0 then call displayerror(1)
  74.  
  75. GETBBSLIST bbslist
  76. if rc ~= 0 then call displayerror(1)
  77.  
  78. if makeresident = 1 then do
  79.     address(command)
  80.     'Resident C:List PURE'
  81.     end
  82.  
  83. if bbslist.COUNT > 0 then do i = 1 to bbslist.COUNT
  84.     address(bbsread)
  85.     GETBBSDATA '"'bbslist.i'"' bbsdata
  86.     if rc ~= 0 then call displayerror(1)
  87.  
  88.     if bbsdata.DNLOADPATH ~= '' then dlpath = bbsdata.DNLOADPATH
  89.     else dlpath = globdata.DNLOADPATH
  90.  
  91.     address(command)
  92.     'List >T:GrabList 'dlpath || bbsdata.GRABNAME'#? LFORMAT "%s"'
  93.  
  94.     if exists("T:GrabList") then do
  95.         glopen = open(gl, "T:GrabList", 'R')
  96.         do until eof(gl)
  97.             entry = readln(gl)
  98.             if entry ~= '' then do
  99.                 if fromthor = 0 then say '1B'x'[1mParsing 'bbsdata.BBSTYPE' grab from 'bbsdata.NAME': "'dlpath || entry'"' || '1B'x'[0m'
  100.  
  101.                 if bbsdata.NUMEVENTS > 0 then do
  102.                     if fromthor = 0 then do
  103.                         say 'There are active events on "'bbsdata.NAME'":'
  104.                         thorpath'bin/ListEvents "'bbsdata.NAME'" FULL'
  105.                         signal off error
  106.                         'Ask "*NDelete these events? [y/N]"'
  107.                         signal on error
  108.                         if rc = 5 then delevents = 1
  109.                         end
  110.                     else do
  111.                         address(thorport)
  112.                         REQUESTNOTIFY '"There are 'bbsdata.NUMEVENTS' active events on\n'bbsdata.NAME'. Delete them?"' '"Yes|No"'
  113.                         if result = 1 then delevents = 1
  114.                         end
  115.  
  116.                     if delevents = 1 then do
  117.                         address(bbsread)
  118.                         do e = bbsdata.FIRSTEVENT to bbsdata.LASTEVENT
  119.                             drop eventdata.
  120.                             READBREVENT '"'bbsdata.NAME'"' EVENTNR e DATASTEM eventdata
  121.                             if rc ~= 0 then call displayerror(0)
  122.                             say eventdata.EVENTTYPE
  123.                             say eventdata.FLAGS
  124.                             if ~bittst(eventdata.FLAGS, EDB_DELETED) & ~bittst(eventdata.FLAGS, EDB_ERROR) & ~bittst(eventdata.FLAGS, EDB_DONE) & ~bittst(eventdata.FLAGS, EDB_FREEZE) then do
  125.                                 say 'Kill''em!'
  126.                                 UPDATEBREVENT BBSNAME '"'bbsdata.NAME'"' EVENTNR e SETDONE
  127.                                 if rc ~= 0 then call displayerror(0)
  128.                                 end
  129.                             end
  130.                         PACKDATAFILE BBSNAME '"'bbsdata.NAME'"' EVENTDATA SHOWPROGRESS
  131.                         if rc ~= 0 then call displayerror(0)
  132.  
  133.                         GETBBSDATA '"'bbslist.i'"' bbsdata
  134.                         if rc ~= 0 then call displayerror(0)
  135.  
  136.                         address(command)
  137.                         if bbsdata.UPLOADPATH ~= '' then ulpath = bbsdata.UPLOADPATH
  138.                         else ulpath = globdata.UPLOADPATH
  139.                         If exists(ulpath||bbsdata.REPLYPACKET) then do
  140.                             'Delete "'ulpath||bbsdata.REPLYPACKET'" QUIET FORCE'
  141.                             end
  142.                         end
  143.                     end
  144.  
  145.                 address(command)
  146.                 thorpath'bin/CfgType >T:TypeInfo 'bbsdata.BBSTYPE
  147.  
  148.                 tiopen = open(ti, "T:TypeInfo", 'R')
  149.                 tmp = readln(ti); tmp = readln(ti); tmp = readln(ti); tmp = readln(ti)
  150.                 parser = subword(tmp, 4); parser = left(parser, index(parser, ',') - 1)
  151.                 call close(ti)
  152.  
  153.                 thorpath || parser' "'bbsdata.NAME'" "'dlpath || entry'" ARCHIVE DELETE PUBSCREEN "'pubscreen'"'
  154.                 end
  155.             end
  156.         call close(gl)
  157.         end
  158.     end
  159.  
  160. break_c:
  161. error:
  162. halt:
  163.  
  164. if fromthor = 1 then do
  165.     address(thorport)
  166.     UNLOCKGUI
  167.     RESCAN
  168.     end
  169.  
  170. address(command)
  171. if glopen then call close(gl)
  172. if exists("T:GrabList") then 'Delete "T:GrabList" QUIET'
  173. if tiopen then call close(ti)
  174. if exists("T:TypeInfo") then 'Delete "T:TypeInfo" QUIET'
  175. if remresident = 1 then 'Resident LIST REMOVE'
  176.  
  177. exit(0)
  178.  
  179.  
  180. displayerror: procedure expose thorport BBSREAD.LASTERROR fromthor
  181.               parse arg finito
  182.  
  183. if fromthor = 0 then say BBSREAD.LASTERROR
  184. else do
  185.     address(thorport)
  186.     REQUESTNOTIFY '"'BBSREAD.LASTERROR'"' '"I see"'
  187.     address(bbsread)
  188.     end
  189.  
  190. if finito = 1 then signal break_c
  191. return
  192.